Skip to content

An SLCN history record takes one route on every rank, an empty rank included - #1237

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/slcn-history-write-on-an-empty-rank
Nov 20, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/slcn-history-write-on-an-empty-rank

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

A follow-up to the review of #1234, which found it. No issue is filed.

What changes

In parallel, SemiLagrangian._record_current_field_into_history records the current field by copying the tracked variable's nodal data (_record_psi_star_from_field_data). On a rank with no nodes:

  • The copy's reshape(0, -1) raised ValueError, because NumPy cannot infer -1 from zero elements.
  • The except returned None, which sent that rank alone to evaluate psi_fn.
  • The two routes enter different collectives, so the step hung.

The reviewer saw this at np 3 with an empty rank. It affects every SLCN solver with an empty rank, not only the level set.

Now:

  • The column counts come from the arrays' trailing shape, so a rank with zero rows takes the copy too.
  • The ranks agree on the route with a logical AND before taking it. If any rank declines the copy, every rank evaluates.

Serial runs are unchanged: the copy is not used serially.

Tolerances and coordinate matches

The test runs two SLCN steps of the steady field x + y twice at the same rank count:

  • on the triangle with one rank empty;
  • on the same triangle shared among every rank.

Both take the parallel route.

  • Values must match to 100 times the solve tolerance (1e-8 at 1e-10). The reviewer measured 2.4e-9 between the two partitions at np 3. The serial and parallel routes differ by 5e-5, so the bound still tells a route change from a partition change.
  • Node positions of the two runs must match to 1e-12.
  • A loose check holds the answer to 1e-4 of x + y. Neither route keeps x + y exactly. In two steps the field moves 7.5e-5 from it serially, where the record nudges nodes towards cell centroids, and 2.5e-5 at np 3, with or without the empty rank. The parallel figures are the reviewer's.
  • Coordinate match: the two runs' nodes are paired by position (rounded to 1e-12, sorted), because two partitions of one triangle share no point numbering. The node count must match.

Tests

tests/parallel/test_1236_slcn_step_on_an_empty_rank_parallel.py: the empty-rank triangle of empty_rank_fixtures, with All_Boundaries marked on every rank, and a 300 s timeout, so a hang fails.

  • It skips below np 3, and scripts/test.sh runs it at np 3.
  • We do not run MPI on this machine (macOS, 12-core Apple M4). The reviewer runs it on this branch and on development, where it should hang.
  • The helpers were checked serially: two builds give the same 45 nodes and values.

Serial SLCN, SUPG and semi-Lagrangian files on this branch: 148 passed, 1 skipped.

Adversarial review (author's pass)

  • Rank asymmetry. The new allreduce runs whenever uw.mpi.size > 1, the same on every rank. The record is reached on every rank, from update_pre_solve. The serial path has no collective.
  • Left as it is: the outer try/except falls back to a projection solve if _history_evaluate raises. An exception raised on some ranks only would still split the ranks. This change does not touch that path.

Underworld development team with AI support from Claude Code

…ncluded

In parallel the semi-Lagrangian history records the current field by copying
the tracked variable's nodal data. On a rank with no nodes the copy's
reshape(0, -1) raised (NumPy cannot infer -1 from zero elements), the
exception sent that rank alone to evaluate psi_fn, and the two routes enter
different collectives: an SLCN step hung at np 3 with an empty rank (found in
the review of #1234). The column counts now come from the arrays' trailing
shape, and the ranks agree on the route with a logical AND.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 19, 2026 21:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…without an empty rank

Both runs take the parallel route, so the comparison does not depend on the
serial record's centroid nudge; a loose check holds x + y.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict at 12f13bb: changes requested. The fix is right. With an empty rank, every rank now takes the same route for the history record. The step that hangs on development completes on this branch, both on the test's triangle and on a gmsh box. One thing blocks the merge: the PR's own new test fails here at np 3. Its value comparison asks for 1e-10 between two partitions, and the two partitions differ by 2.4e-9. The fix is a one-line tolerance change.

The PR changes only .py files. The merge base is 246d6ce. An existing build's compiled sources match it exactly. All the .py files of the merge base, and of the PR head, were each laid over a copy of that build's install. That install had been partly overwritten by another review, so after laying the overlays I diffed every installed .py file against the intended source tree. Each overlay matches its tree exactly, apart from the build-generated _uwid.py. #1234 is still open, so the box probe ran on this branch alone. The empty-rank runs use a shell partition into horizontal bands, with the last rank given no cells.

Findings

  1. High: test_1236 fails at np 3 on this branch.

    The assertion with_empty[:, 2] == without[:, 2] to atol=1e-10 fails on 21 of 45 nodes, with a largest difference of 2.438e-9; for example 0.25002532918 against 0.250025329573. The positions match exactly. A separate probe that runs the same two steps gives the same 2.438e-9, so the difference is deterministic and not noise.

    The difference is the partition's effect on an iterative solve at adv.tolerance = 1e-10. That is the "partition round-off" the test's docstring allows for, but 1e-10 is tighter than the solve delivers. scripts/test.sh now runs this test at np 3, so the parallel job would go red.

    Suggested fix: atol=1e-8 on the values, or a tolerance tied to adv.tolerance. That still separates a partition difference (1e-9) from the route difference between the two paths (5e-5, below), which is what the test is meant to catch. The loose check |T - (x + y)| < 1e-4 is not reached; on this partition it is 2.5e-5, as measured by the probe.

Probes

The new test at np 3.

  • On development it hangs: the supervisor reports rank 2 (the empty rank) in update_lvec(). It was stopped at the outer timeout.
  • On the branch it runs to the end in 7 s and fails on finding 1.

The record's route on each rank. I instrumented SemiLagrangian._record_psi_star_from_field_data (the local direct copy) and _history_evaluate (the evaluate route) on the test's triangle, for two steps.

  • np 1: every record takes the evaluate route; the direct copy is never tried (np 1 has no old frame).

  • np 3 shared among every rank (cells 6 / 5 / 5): the same sequence on all three ranks.

  • np 3 with an empty rank (cells 8 / 8 / 0): the same sequence on all three ranks, including the empty one. Its direct copy now returns zero rows rather than raising.

    The sequence in both np 3 cases: at each step the first record is a direct copy on every rank, and the second returns None on every rank and goes to evaluate.

  • The LAND reduction never had to override a rank here, because every rank agreed locally. It guards against a rank-local failure in the copy.

np 1 against np 3 (two steps on the test's triangle, the field x + y):

run max |T − (x+y)| max |T − T_np1|
np 1 7.498e-5 —
np 3, every rank with cells 2.533e-5 4.965e-5
np 3, one rank empty 2.533e-5 4.965e-5

Node positions agree exactly across all three runs. The author's 7.5e-5 is np 1's distance from x + y: serially the record takes the nudged evaluate route. The np 3 to np 1 difference is 5.0e-5, smaller than that, because the np 3 copy route sits closer to x + y. Both are well inside the test's 1e-4.

Empty rank on a gmsh box (np 3, cells 121 / 121 / 0, three SLCN steps of a rotating flow):

  • On development it hangs: rank 2 is in update_lvec().
  • On the branch all three steps complete on every rank. The range of T is 0 to 1.99249, 1.98557 and 1.97909 after steps 1, 2 and 3.

What was run

  • The new test at np 3: development hangs; the branch fails on finding 1.
  • Route instrumentation and value comparison: np 1, np 3, and np 3 with an empty rank.
  • The box probe at np 3 with an empty rank: development and branch.
  • SLCN, semi-Lagrangian and DDt tests, serially on the branch, 9 files: 62 passed, 0 failed.

Not run:

  • the full serial and parallel suites;
  • #1234 together with this branch, because #1234 has not merged;
  • anything above np 3.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

… tolerance (review of #1237)

At a tolerance of 1e-10 two partitions differ by 2.4e-9 (measured by the
reviewer at np 3); the bound is now 100 times the tolerance. The docstring
gives the reviewer's route numbers: neither route holds x + y exactly.

Underworld development team with AI support from Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants